package io.gitee.chearnee.fw.theadpool.property;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2021/8/27 12:10
 */
@Getter
@Setter
@ConfigurationProperties(prefix = "fw.config.pool")
public class ThreadPoolProperties {

  /**
   * 核心线程数
   */
  private int corePoolSize = 20;
  /**
   * 最大线程数
   */
  private int maxPoolSize = 100;
  /**
   * 允许线程空闲时间（单位：默认为秒）
   */
  private int keepAliveTime = 10;
  /**
   * 缓冲队列大小
   */
  private int queueCapacity = 200;
  private String threadNamePrefix = "fw-async-Service-";
  /**
   * ttl线程池(beanName:ttlTaskExecutor)
   */
  private TTL ttl;
  /**
   * 拒绝策略
   */
  private Class<? extends RejectedExecutionHandler> rejectedExecutionHandler = CallerRunsPolicy.class;

  @Getter
  @Setter
  public static class TTL {

    /**
     * 开启ttl(TransmittableThreadLocal)
     *
     * @link https://github.com/alibaba/transmittable-thread-local
     */
    private Boolean enabled = true;
  }

}
